import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import CLIPSJNI.Environment;


/* Implement FindFact which returns just a FactAddressValue or null */
/* TBD Add size method to PrimitiveValue */

class ConocimientosPrevios extends JPanel {

    /**
     * 
     */
    private static final long serialVersionUID = 6346945039630385672L;

    JLabel dLabel;

    JComboBox matematica;
    JComboBox lengua;
    JComboBox sociales;
    JComboBox naturales;
    JComboBox arte;

    
    JButton nextButton;
    JButton prevButton;
    JPanel choicesPanel;
    ButtonGroup choicesButtons;

	
	PrintWriter writer;

    Environment clips;

    public ConocimientosPrevios()  {
      

        /* ================================ */
        /* Create a new JFrame container. */
        /* ================================ */

        final JFrame jfrm = new JFrame("TestVocacionalDemo");

        /* ============================= */
        /* Specify FlowLayout manager. */
        /* ============================= */

        jfrm.getContentPane().setLayout(new GridLayout(1, 1));

        /* ================================= */
        /* Give the frame an initial size. */
        /* ================================= */

        jfrm.setSize(750, 300);
        jfrm.setLocation(200, 100);

        /* ============================================================= */
        /* Terminate the program when the user closes the application. */
        /* ============================================================= */

        jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        /* =========================== */
        /* Create the display panel. */
        /* =========================== */

        JPanel displayPanel = new JPanel();
        JLabel displayLabel = new JLabel();
        displayPanel.add(displayLabel);

        /* =========================== */
        /* Create the choices panel. */
        /* =========================== */

        choicesPanel = new JPanel();
        choicesPanel.setBorder(BorderFactory.createTitledBorder("Conocimientos previos del alumno"));
       
		
        
        choicesPanel.setSize(400, 400);
        choicesPanel.setLayout(new BoxLayout(choicesPanel, BoxLayout.Y_AXIS));
		
        dLabel = new JLabel("Matematica");
        choicesPanel.add(dLabel);
        matematica = new JComboBox();
        matematica.addItem("alto");
        matematica.addItem("medio");
        matematica.addItem("bajo");
        choicesPanel.add(matematica);

        dLabel = new JLabel("Lengua");
        choicesPanel.add(dLabel);
        lengua = new JComboBox();
        lengua.addItem("alto");
        lengua.addItem("medio");
        lengua.addItem("bajo");
        choicesPanel.add(lengua);

        dLabel = new JLabel("Sociales");
        choicesPanel.add(dLabel);
        sociales  = new JComboBox();
        sociales.addItem("alto");
        sociales.addItem("medio");
        sociales.addItem("bajo");
        choicesPanel.add(sociales);

        dLabel = new JLabel("Naturales");
        choicesPanel.add(dLabel);
        naturales  = new JComboBox();
        naturales.addItem("alto");
        naturales.addItem("medio");
        naturales.addItem("bajo");
        choicesPanel.add(naturales);

        dLabel = new JLabel("Arte");
        choicesPanel.add(dLabel);
        arte = new JComboBox();
        arte.addItem("alto");
        arte.addItem("medio");
        arte.addItem("bajo");
        choicesPanel.add(arte);

     
        /* =========================== */
        /* Create the buttons panel. */
        /* =========================== */

        
        try {
            writer = new PrintWriter("factsConocimiento.clp", "UTF-8");

        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (UnsupportedEncodingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        JPanel buttonPanel = new JPanel();

  

        nextButton = new JButton("Next");
        nextButton.setActionCommand("Next");
        choicesPanel.add(nextButton);
        nextButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                AptitudPanel aptPanel = new AptitudPanel();
				
				
				writer.println("(deffacts caso_3 " );
				writer.println("	(conocimientos_previos " );
				writer.println("		(matematica "+matematica.getSelectedItem().toString()+")");
				writer.println("		(lengua "+lengua.getSelectedItem().toString()+")");
				writer.println("		(sociales "+sociales.getSelectedItem().toString()+")" );
				writer.println("		(naturales "+naturales.getSelectedItem().toString()+")");
				writer.println("		(arte "+arte.getSelectedItem().toString()+")))");
				writer.close();
				
                aptPanel.setVisible(true);
                jfrm.setVisible(false);

				

            }
        });

        /* ===================================== */
        /* Add the panels to the content pane. */
        /* ===================================== */

        jfrm.getContentPane().add(displayPanel);
        jfrm.getContentPane().add(choicesPanel);
        jfrm.getContentPane().add(buttonPanel);

        /* ==================== */
        /* Display the frame. */
        /* ==================== */

        jfrm.setVisible(true);
        displayLabel.setText("Run clips file");
        /* ================================== */
        /* Get the current state of the UI. */
        /* ================================== */

    }


}
